class FacebookController < ApplicationController
  ensure_authenticated_to_facebook

  layout nil
  
  
  
  def get_user
    redirect_to :controller => :users, :action => :new    
  end
  
  def create_event 
    unless session[:facebook_session].user.has_permission?("create_event")
      redirect_to "http://www.facebook.com/authorize.php?api_key=c87e428c22ca1eb208e624af60f7e6eb&v=1.0&ext_perm=create_event"
    else
      #event = Event.find(:first,:include => [:place,:location],:conditions => {:id => params[:id]})
      event = Event.new
      start_time = (Time.now + 24.hours).utc.to_i
      end_time = (Time.now + 90.hours).utc.to_i
  
      id = session[:facebook_session].create_event({
          'name' => "event",#event.name,
          'category' => "Party",#event.facebook_category.to_s,
          'subcategory' => 'Birthday Party', #event.facebook_subcategory.to_s,
          'host' => "posto",#event.organizers.blank? ? event.place.title :
          'location' => "posto",#event.place.title,
          'street' => "via",#event.place.address,
          'city' => "citta",#event.city.to_s,
          'description' => "descrizion",#event.description || '',
          'privacy_type' => 'SECRET',
          'start_time' => start_time,
          'end_time' => end_time
        })
        render :text => "http://www.facebook.com/event.php?eid=#{id}&index=1" 
    end



  end
  
  
end
